/*
Copyright SecureKey Technologies Inc. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
*/

package invoke

import (
	reqContext "context"
	"time"

	pb "git.cloud.inspur.com/ichain/ichain-protos-go/inode"
	"git.cloud.inspur.com/ichain/ichain-sdk-go/pkg/common/errors/retry"
	"git.cloud.inspur.com/ichain/ichain-sdk-go/pkg/providers/core"
	"git.cloud.inspur.com/ichain/ichain-sdk-go/pkg/providers/ichain"
)

type Opts struct {
	Targets       []ichain.Inode // targets
	Retry         retry.Opts
	BeforeRetry   retry.BeforeRetryHandler
	Timeouts      map[ichain.TimeoutType]time.Duration
	ParentContext reqContext.Context //parent grpc context
}

type Request struct {
	ContractID      string
	Fcn             string
	Args            [][]byte
	TransientMap    map[string][]byte
	InvocationChain []*ichain.ContractCall
	IsInit          bool
}

type Response struct {
	Proposal         *ichain.TransactionProposal
	Responses        []*ichain.TransactionProposalResponse
	TransactionID    ichain.TransactionID
	TxValidationCode pb.TxValidationCode
	ContractStatus   int32
	Payload          []byte
}

type Handler interface {
	Handle(context *RequestContext, clientContext *ClientContext)
}

type ClientContext struct {
	CryptoSuite  core.CryptoSuite
	Discovery    ichain.DiscoveryService
	Membership   ichain.ChainMembership
	Transactor   ichain.Transactor
	EventService ichain.EventService
}

type RequestContext struct {
	Request      Request
	Opts         Opts
	Response     Response
	Error        error
	RetryHandler retry.Handler
	Ctx          reqContext.Context
}
